<template>
  <div>
    <CityHeader></CityHeader>
    <CitySearch :cities='cities'></CitySearch>
    <List :hotCities='hotCities' :cities='cities' :letter='itemletter'></List>
    <CityAlphabet :cities='cities' @change="handleLtter"></CityAlphabet>
  </div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/CityHeader'
import CitySearch from './components/CitySearch'
import List from './components/List'
import CityAlphabet from './components/Alphabet'

export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    List,
    CityAlphabet
  },
  data () {
    return {
      hotCities: [],
      cities: {},
      itemletter: ''
    }
  },
  mounted () {
    this.getCityinfo()
  },
  methods: {
    getCityinfo () {
      axios.get('/api/city.json')
        .then(this.getCityinfocc)
    },
    getCityinfocc (res) {
      res = res.data
      if (res.ret && res.data) {
        this.hotCities = res.data.hotCities
        this.cities = res.data.cities
      }
    },
    handleLtter (letter) {
      this.itemletter = letter
    }
  }
}
</script>

<style lang="stylus" scoped>

</style>
